<template>
    <div class="content">
      <div class="accountCon">
        <!--列表-->
        <el-row>
          <el-col :span="24">
            <el-table
              :data="list"
              size="small"
              border
              v-loading="loading"
              :cell-style="$style.cellStyle"
              :header-cell-style="$style.rowClass"
              @selection-change="handleSelectionChange"
            >
              <ElTableColumn label="id" prop="id" width="50"/>
              <ElTableColumn label="员工名称" prop="realname" width="100" />
              <ElTableColumn label="员工电话" prop="mobile" width="100" />
              <!-- <ElTableColumn label="门店" prop="shop_name" /> -->
              <ElTableColumn label="门店" prop="shopName" />
              <ElTableColumn label="操作" fixed="right" width="120">
                <template slot-scope="{ row }">
                  <span
                    class="theme ml20"
                    @click="tapBtn(row)"
                  >编 辑</span>
                </template>
              </ElTableColumn>
            </el-table>
          </el-col>
        </el-row>
      </div>
      <!-- 编辑弹框 -->
      <el-dialog
        :title="`${title}`"
        :visible.sync="showRole"
        :close-on-click-modal="false"
        width="600px"
        top="40px"
        class="add"
        >
        <el-form  label-position="top" size="mini">
            <!-- <el-form-item label="角色名称" prop="title">
            <span>{{ this.staff_name }}</span>
            </el-form-item> -->
            <el-form-item label="门店选择" >
                <el-select
                    v-model="shopId"
                    multiple
                    collapse-tags
                    style="margin-left: 20px;"
                    placeholder="请选择">
                    <el-option
                    v-for="item in shopList"
                    :key="item.shop_id"
                    :label="item.shop_name"
                    :value="item.shop_id">
                    </el-option>
                </el-select>
                </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" size="small" @click="clickSubmit()">确 定</el-button>
            <el-button size="small" @click="showRole = false">取 消</el-button>
        </div>
        </el-dialog>
    </div>
  </template>
  
  <script>
  import { mapGetters } from "vuex";
  import pagination from "@/components/Pagination";
  import {
    getAgentList,
    getAgentShopList,
    setShopAgent
  } from "@/api/staff";
  export default {
    name: "OrderList",
    components: {
      pagination
    },
    data() {
      return {
        // page: new Page(), // 分页
        list: [], // 数据展示
        idList: "",
        loading: false,
        showRole : false,
        title:"",
        user:[],
        shopId:[],
        staff_name:"",
        staffId:""
      };
    },
    computed: {
      ...mapGetters(["userInfo"])
    },
    mounted() {
      this.getOptions();
      this.getList();
    },
    methods: {
      // 获取列表
      getList() {
        this.loading = true;
        getAgentList({ ...this.search, ...this.page }).then(res => {
          this.list = res;
          this.loading = false;
        });
      },
      clickSubmit(){
        setShopAgent({'id':this.staffId,'shop_ids':this.shopId}).then(res => {
          if(res.data == true)
          {
            this.showRole = false;
            this.$message({
                message: '修改成功',
                type: 'success'
            });
          }
          this.getList();
        });
      },
          // 获取选项
     tapBtn(row)
      {
        // const data = await roleDetail({
        //     id: item.id
        //   });
          this.title = "编辑";
          this.showRole = true;
          this.shopId = row.shopId;
          this.staff_name = row.realname;
          this.staffId = row.id;

          
      },
      getOptions(){
        getAgentShopList({ ...this.search, ...this.page }).then(res => {
          this.shopList = res;
        });
      }
    }
  };
  </script>
  
  <style lang="scss" scoped>
  .bgW {
    background: #fff;
    border-radius: 3px;
    margin-bottom: 20px;
  }
  .el-form-item {
    margin: 5px 40px 3px 0;
  }
  .accountCon {
    background: #fff;
    padding: 10px 0px 80px;
  }
  .footerBtn {
    text-align: right;
  }
  </style>
  